package com.ocom.payconfig.controller;

import com.ocom.common.constant.PayConfigUrl;
import com.ocom.common.entity.master.EntityPayChannel;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.request.web.DelPayChannelRequest;
import com.ocom.common.request.web.EditPayChannelRequest;
import com.ocom.common.request.web.GetPayChannelRequest;
import com.ocom.common.request.web.SavePayChannelRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.payconfig.service.PayChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PayChannelController {

	@Autowired
	private PayChannelService payChannelService;

	@PostMapping(PayConfigUrl.URLP_getPageChannel)
	public Result getPageChannel(@RequestBody GetPayChannelRequest request){
		return payChannelService.getPayChannelList(request);
	}

	@PostMapping(PayConfigUrl.URLP_addPageChannel)
	public Result addPageChannel(@RequestBody SavePayChannelRequest request){
		EntityPayChannel entityPayChannel= payChannelService.addPageChannel(request);
		if(entityPayChannel!=null){
			return ResultUtil.success(entityPayChannel);
		}
		return ResultUtil.error(ResultEnum.Err_2016);
	}

	@PostMapping(PayConfigUrl.URLP_editPageChannel)
	public Result editPageChannel(@RequestBody EditPayChannelRequest request){
		EntityPayChannel entityPayChannel= payChannelService.editPayChannel(request);
		if(entityPayChannel!=null){
			return ResultUtil.success(entityPayChannel);
		}
		return ResultUtil.error(ResultEnum.Err_3014);
	}

	@PostMapping(PayConfigUrl.URLP_delPageChannel)
	public Result delPageChannel(@RequestBody DelPayChannelRequest request){
		boolean b =payChannelService.delPageChannel(request);
		if(b){
			return ResultUtil.success();
		}else{
			return ResultUtil.error(ResultEnum.Err_3016);
		}
	}


	@PostMapping(PayConfigUrl.URLP_getPageChannelKey)
	public Result getPageChannelKey(Integer payWay){
		return ResultUtil.success(payChannelService.getPayTipByCode(payWay));
	}


	@PostMapping(PayConfigUrl.URLP_getPageChannelKeyByCode)
	public Result getPageChannelKeyByCode(Integer  payWay){
		return ResultUtil.success(payChannelService.getPayTipByCode(payWay));
	}

}
